# -*- coding: utf-8 -*-
"""
Created on Fri Aug  1 10:37:47 2025

@author: pc
"""

name = 'z'

with open(name+'_position.txt','r') as file:
    binary_code_1 = file.read()

encoded_str = binary_code_1

base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    
    # 创建字符到索引的映射字典
char_to_index = {char: index for index, char in enumerate(base64_chars)}
    
    # 移除可能存在的填充字符'='并计算填充长度
padding_length = encoded_str.count('=')
encoded_str = encoded_str.rstrip('=')
    
    # 将每个字符转换为6位二进制并连接起来
binary_str = ''
for char in encoded_str:
    if char in char_to_index:
        binary_str += f"{char_to_index[char]:06b}"
    
    # 移除填充添加的额外位
if padding_length:
    binary_str = binary_str[:-(padding_length * 2)]
    # 将8位一组分割并转换为字节
decoded_bytes = bytearray()
for i in range(0, len(binary_str), 8):
    byte_str = binary_str[i:i+8]
    if len(byte_str) == 8:
        decoded_bytes.append(int(byte_str, 2))

with open(name+'_location_binary_data.txt','w') as f:
    f.write(binary_str)
        
f.close()

